<!DOCTYPE HTML>
<html>
<head>
    <title>Todo</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <link rel="stylesheet" href="/editor/common.css">
</head>
<body  style="padding: 0;width: 100%;height: 100%">
<div class="mini-splitter" style="width:100%;height:100%;">
    <div size="240" showCollapseButton="true">
        <div class="mini-fit">
            <ul id="tree1" class="mini-tree"  url="/json/orderTree.json" style="width:100%;"
                showTreeIcon="true" textField="name" idField="id" onnodeclick="onNodeDblClick" parentField="pid" resultAsTree="false"
            >
            </ul>
        </div>
    </div>
    <div showCollapseButton="true">
        <div id="outImg">
            <img id="imgId" src="" alt="" onclick="smallImg()">
        </div>
        <div style="padding: 5px">
            <span>买家ID：</span><input  class="mini-textbox" type="text" id="buyerOId"/>
            <span>收货人：</span><input  class="mini-textbox" type="text" id="receiver"/>
            <span>订单号：</span><input  class="mini-textbox" type="text" id="orderCode"/>
            <span>店铺名称：</span><input  class="mini-textbox" type="text" id="shopName"/>
            <span>买家昵称：</span><input  class="mini-textbox" type="text" id="buyerUser"/>
            <a class="mini-button" iconCls="icon-search" onclick="search()">查找</a>
        </div>
        <div style="width:99%;">
            <div class="mini-toolbar" style="border-bottom:0;padding:0;">
                <table style="width:100%;">
                    <tr>
                        <td style="width:100%;">
                            <!--<a class="mini-button" iconCls="icon-add" onclick="shopMangerAdd()">增加</a>-->
                            <a id="refund" style="display: none" class="mini-button" iconCls="icon-add" onclick="shopMangerEdit()">编辑</a>
                            <a id="receipt" style="display: none" class="mini-button" iconCls="icon-add" onclick="receipt()">确认收货</a>
                            <a id="sendGoods" style="display: none" class="mini-button" iconCls="icon-add" onclick="send()">发货</a>
                            <!--<a class="mini-button" iconCls="icon-remove" onclick="shopMangerRemove()">删除</a>-->
                        </td>
                    </tr>
                </table>
            </div>
        </div>

        <div id="datagrid1" class="mini-datagrid" style="width:99%;height: 82%;"
             url="/getdata/shopOrder" idField="id" allowResize="true"
             sizeList="[20,30,50,100]" pageSize="30"
             onshowrowdetail="onShowRowDetail"
        >
            <div property="columns">
                <div type="expandcolumn" >#</div>
                <div field="objectId" width="120" headerAlign="center" allowSort="true">订单id
                    <input property="editor" class="mini-textbox" />
                </div>
                <div field="status" width="80" allowSort="true" renderer="statusRenderer" align="center" headerAlign="center">订单状态</div>
                <div field="goodsPicURL" width="50" allowSort="true"  align="center" headerAlign="center">商品图片</div>
                <div field="goodsOId" width="80" allowSort="true" renderer="picRenderer" align="center" headerAlign="center">商品详情</div>
                <div field="orderCode" width="100" align="center" headerAlign="center" allowSort="true">订单号</div>
                <div field="totalPrice" width="50" align="center" headerAlign="center" allowSort="true">付款金额</div>
                <div field="phone" width="100"  align="center" headerAlign="center" allowSort="true">电话号码</div>
                <div field="shopName" width="100"  align="center" headerAlign="center" allowSort="true">店铺名称</div>
                <div field="shopUserName" width="100"  align="center" headerAlign="center" allowSort="true">店主</div>
                <div field="payType" width="70" align="center" headerAlign="center" renderer="payTypeRenderer" allowSort="true">支付方式</div>
                <div field="receiver" width="100" align="center" headerAlign="center" allowSort="true" >收货人</div>
                <div field="expressCode" width="100" align="center" headerAlign="center" allowSort="true" >快递编号</div>
                <div field="logisticsCom" width="100" align="center" headerAlign="center" allowSort="true" >物流公司</div>
                <div field="deliverTime" width="100" align="center" headerAlign="center" dateFormat="yyyy-MM-dd hh:mm:ss" allowSort="true">发货时间</div>
                <div field="payTime" width="100" align="center" headerAlign="center" dateFormat="yyyy-MM-dd hh:mm:ss" allowSort="true">付款时间</div>
                <div field="createdAt" width="100" align="center" headerAlign="center" dateFormat="yyyy-MM-dd hh:mm:ss" allowSort="true">创建日期</div>
            </div>
        </div>
        <div id="editForm1" style="display:none;">
            <div  class="mini-tabs" style="width:100%;" activeIndex="0">
                <div title="收货人信息">
                    <input class="mini-hidden" name="id"/>
                    <table style="width:100%;">
                        <tr style="height: 50px">
                            <td style="width: 80px;">买家：</td>
                            <td style="width:150px;"><input name="buyerId" class="mini-textbox" /></td>
                            <td style="width:80px;">收货人：</td>
                            <td style="width:150px;"><input name="receiver" class="mini-textbox" /></td>
                            <td style="width:80px;">昵称：</td>
                            <td style="width:150px;"><input name="buyerName" class="mini-textbox" /></td>
                            <td style="width: 80px;">收货地址：</td>
                            <td style="width: 300px"><input name="address" style="width: 300px" class="mini-textbox" /></td>
                        </tr>
                        <tr style="height: 50px" >
                            <td style="width:150px; display: none"><input name="objectId" class="mini-textbox" /></td>
                        </tr>

                    </table>
                </div>
                <div title="商品信息">
                    <input class="mini-hidden" name="goods"/>
                    <table style="width:100%;">
                        <tr style="height: 50px">
                            <td style="width:80px;">购买数量：</td>
                            <td style="width:150px;"><input name="num" class="mini-textbox" /></td>
                            <td style="width:80px;">购买规格：</td>
                            <td style="width:150px;"><input name="goodsModel" class="mini-textbox" /></td>
                            <td style="width: 80px;">商品价格：</td>
                            <td style="width: 150px"><input name="price"  class="mini-textbox" /></td>
                            <td style="width: 80px;">商品名称：</td>
                            <td style="width:80px;"><input name="goodsName" class="mini-textbox" style="width: 300px"/></td>
                        </tr>
                        <tr style="height: 50px" >
                            <td style="width:80px;">团购价格：</td>
                            <td><input name="groupPrice" class="mini-textbox" /></td>
                            <td style="width:80px;">物流信息：</td>
                            <td><div   id="context"  ></div></td>
                            <td style="width:150px; display: none"><input name="" class="mini-textbox" /></td>
                        </tr>

                    </table>

                </div>
            </div>
            <div style="text-align:right;padding-top:5px;padding-right:20px;" colspan="6">
                <a class="Update_Button" href="javascript:updateRow();">提交</a>
                <a class="Cancel_Button" href="javascript:cancelRow();">取消</a>
            </div>
        </div>
    </div>
</div>
</body>
<script src="/scripts/jquery.min.js"></script>
<script src="/scripts/miniui/miniui.js"></script>
<script type="text/javascript">
    mini.parse();
    var flag = 1;
    var editForm = document.getElementById("editForm1");
    var refund = document.getElementById("refund");
    var receipt = document.getElementById("receipt");
    var sendGoods = document.getElementById("sendGoods");
    var tree = mini.get("tree1");
    var grid = mini.get("datagrid1");
    grid.load();
    function onNodeDblClick(e) {
        var receiver = mini.get("receiver").getValue();
        var orderCode = mini.get("orderCode").getValue();
        var shopName = mini.get("shopName").getValue();
        var buyerUser = mini.get("buyerUser").getValue();
        var buyerOId = mini.get("buyerOId").getValue();
        flag = e.node.id;
        if (flag==-3){
            refund.style.display=''
        }else{
            refund.style.display='none'
        }
        if (flag==2){
            sendGoods.style.display=''
        }else{
            sendGoods.style.display='none'
        }
        if (flag==3){
            receipt.style.display=''
        }else{
            receipt.style.display='none'
        }
        grid.load({
            status: e.node.id,
            receiver: receiver,
            orderCode: orderCode,
            shopName: shopName,
            buyerUser: buyerUser,
            buyerOId: buyerOId,
        });
    };

    grid.on("drawcell", function (e) {
        var  value = e.value;
        column = e.column;
        //将性别文本替换成图片
        if (column.field == "goodsPicURL") {
            if(value) {
                e.cellHtml = '<img class="bigImg" onclick="bigImg()" src="' + value + '?imageMogr2/thumbnail/640x/format/jpg/interlace/1/auto" width="30" height="30" alt="图片">';
            }else{
                e.cellHtml = '<img class="bigImg" onclick="bigImg()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
            }
        }
    });

    function search() {
        var receiver = mini.get("receiver").getValue();
        var orderCode = mini.get("orderCode").getValue();
        var shopName = mini.get("shopName").getValue();
        var buyerUser = mini.get("buyerUser").getValue();
        var buyerOId = mini.get("buyerOId").getValue();
        grid.load({
            receiver: receiver,
            orderCode:orderCode,
            shopName:shopName,
            buyerUser:buyerUser,
            buyerOId:buyerOId,
        });
    }
    function searchStatus() {
        var status = mini.get("status").getValue();
        grid.load({
            status: status
        });
    }
    $("#receiver,#orderCode,#shopName,#buyerUser,#buyerOId").bind("keydown", function (e) {
        if (e.keyCode == 13) {
            search();
        }
    });


    function shopMangerEdit() {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "getdata/updateOrder/refund?id="+row.objectId,
                title: "退款信息信息", width: 600, height: 400,

                ondestroy: function (action) {

                    grid.reload();

                }
            });

        } else {
            alert("请选中一条记录");
        }

    }
    function receipt() {
        var row = grid.getSelected();
        if (row) {
            $.ajax({
                url:"/getdata/updateOrder/updateStatus",
                type:'POST',
                data:{
                    objectId:row.objectId,
                    status:5
                },
                success:function (result) {
                    grid.reload();
                }
            });
        } else {
            alert("请选中一条记录");
        }

    }
    function send() {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "getdata/updateOrder/send?id="+row.objectId,
                title: "发货信息信息", width: 600, height: 400,

                ondestroy: function (action) {

                    grid.reload();

                }
            });

        } else {
            alert("请选中一条记录");
        }

    }


    function bigImg() {
        var row = grid.getSelected();
        if (row) {
            var path = row.goodsPicURL;
            $("#imgId").attr('src', path);
            $("#outImg").css('display','block');
        }
    }
    function smallImg() {
        $("#outImg").css('display','none');
    }


    function statusRenderer(e) {
        var value = e.value;
        if (value==-3) {
            return (value, '买家申请退款')
        }else if(value==-2){
            return (value, '退款成功')
        }else if(value==-1){
            return (value,'卖家同意退款')
        }else if(value==0){
            return (value,'取消的订单')
        }else if(value==1){
            return (value,'未付款')
        }else if(value==2){
            return (value,'待发货')
        }else if(value==3){
            return (value,'待收货')
        }else if(value==4){
            return (value,'已收货')
        }else if(value==5){
            return (value,'订单结束')
        }
    };
    function payTypeRenderer(e) {
        var value = e.value;
        if (value==1) {
            return (value, '支付宝')
        }else if(value==2){
            return (value, '微信')
        }else{
            return (value, '无')
        }
    }
    function picRenderer(e) {
        var value = e.value;
        if (value.status=='app') {
            return (value, '<a href="http://health.aladada.com/goods/info?id=' + value.objectId + '" target="view_window">App商品</a>')
        }else if(value.status=='group'){
            return (value, '<a href="http://health.aladada.com/groups/groupBuying?fgOId=' + value.objectId + '" target="view_window">团购商品</a>')
        }else{
            return (value,'<span>无商品</span>')
        }
    }
    ////////////////////////////////////////////////////
//    function onGenderRenderer(e) {
//        for (var i = 0, l = Genders.length; i < l; i++) {
//            var g = Genders[i];
//            if (g.id == e.value) return g.text;
//        }
//        return "";
//    }

    function onShowRowDetail(e) {
        var row = e.record;

        //将editForm元素，加入行详细单元格内
        var td = grid.getRowDetailCellEl(row);
        td.appendChild(editForm);
        editForm.style.display = "";

        //表单信息
        var form = new mini.Form("editForm1");
        if (grid.isNewRow(row)) {
            form.reset();
        } else {
            grid.loading();
            $.ajax({
                url: "/getdata/shopOrderInfo?objectId=" + row.objectId,
                success: function (text) {
                    $("#context").empty();
                    var o = mini.decode(text);
                    var log = o.logObj;
                    form.setData(o.result.data[0]);
                    if(log.data==''){
                        $("#context").append('<span>无物流信息</span>');
                    }else {
                        var logLen = log.data.length;
                        for (var i=logLen-1;i>=0;i--){
                            $("#context").append('<p style="width: 600px;margin-top: 10px">'+log.data[i].context+log.data[i].time+'</p>');
                        }
                    }

                    grid.unmask();
                }
            });
        }
    }
    function cancelRow() {
        grid.reload();
    }

    function updateRow() {
        var form = new mini.Form("editForm1");
        var o = form.getData();
        grid.loading("保存中，请稍后......");
        var json = mini.encode(o);
        $.ajax({
            url: "/getdata/updateOrder/buyer",
            type:'POST',
            data: { data: json },
            success: function (text) {
                grid.reload();
            },
            error: function (error) {
                console.log(error)
            }
        });

    }
</script>
</html>